<template>
  <u-row
      class="progress-circle"
      @click.native.stop="onTableClick"
      style="background: white"
      v-if="options"
  >
    <u-col
        ref="title"
        class="title"
        v-if="title != null && title !== ''"
        :span="12"
        :style="{
          flex: 0.05,
		  'color': options.title.textStyle.color,
		  'font-size': options.title.textStyle.fontSize + 'px',
		  'font-weight': options.title.bold ? 600 : undefined,
		  'text-align': options.title.left,
		  'font-style': options.title.italics ? 'italic' : undefined
	  }"
    >
      {{ title }}
    </u-col>

    <u-col class="progress-circle-container"
           :span="12"
           :key="index">
      <view class="progress-circle-wrapper"
            @dblclick="onDblClick">
        <u-circle-progress
            :active-color="options.seriesSetting.color"
            :percent="percentage"
            :width="options.seriesSetting.width || 400"/>
        <view class="progress-text"
              :style="{
			bold: options.seriesSetting.textStyle.bold,
			italics: options.seriesSetting.textStyle.italics,
			color: options.seriesSetting.textStyle.color,
			fontStyle: options.seriesSetting.textStyle.italics ?
				'italic' : undefined,
			fontWeight: options.seriesSetting.textStyle.bold ?
				'bold' : undefined,
			fontSize: options.seriesSetting.textStyle.fontSize + 'px'
		}">
          <view class="text" v-html="getProgressText"></view>
        </view>
      </view>
    </u-col>
  </u-row>
</template>

<script>
import chartMixins from './chartMixins.js';

export default {
  name: 'progressCircle',
  props: {
    // 数据
    data: {
      type: [Object, Array]
    },
    // 设置
    options: {
      type: Object
    },
    widget: {
      type: Object
    }
  },
  mixins: [chartMixins],
  components: {},
  data() {
    return {
      ready: false,
      index: 0
    };
  },
  mounted() {
  },
  watch: {
    'options.seriesSetting': {
      handler(val) {
        console.log(this.index)
        this.index++
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    onTableClick() {
      this.$emit('click');
    },
    onDblClick() {
      this.$emit('dblclick', this.dataObject);
    }
  },
  computed: {
    title() {
      if (
          this.options == null ||
          this.options.title == null ||
          !this.options.title.show
      ) {
        return undefined;
      }
      return this.options ? this.options.title.text : undefined;
    },
    getTitleStyle() {
      if (this.options == null || this.options.title == null) return undefined;
      return {
        color: this.options.title.textStyle.color,
        'font-size': this.options.title.textStyle.fontSize + 'px',
        'font-weight': this.options.title.bold ? 600 : undefined,
        'text-align': this.options.title.left,
        'font-style': this.options.title.italics ? 'italic' : undefined
      };
    },
    getProgressText() {
      return this.options && this.options.seriesSetting.textStyle.text.replace(
          '{percent}',
          this.percentage
      );
    },
    percentage() {
      if (!this.getDataPropertyName('progressColumn')) return 0;
      return Number((this.getDataNumber('progressColumn') / this.options.seriesSetting.maxValue).toFixed(2)) * 100;
    }
  }
};
</script>

<style scoped>
.progress-circle {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.progress-circle .title {
  padding: 0px 4rpx;
  height: 80rpx;
  line-height: 60rpx;
  border-bottom: solid 1px #f6f6f6;
  flex-grow: 0;
  flex-shrink: 0;
}

.progress-circle-container {
  height: calc(100% - 80rpx) !important;
  flex: auto !important;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  box-sizing: border-box;
  padding-top: 20rpx;
  width: 100%;
}

.progress-circle-wrapper {
  display: inline-block;
  text-align: center;
  width: 100%;
  height: 100%;
  position: relative;
}
.u-circle-progress{
  height: 100% !important;
}

.progress-text {
  position: absolute;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
  width: 100%;
  text-align: center;
  display: inline-block;
  vertical-align: middle;
  z-index: 1000;
}

.progress-text::before {
  content: "";
  height: 100%;
  width: 0px;
  display: inline-block;
  vertical-align: middle;
}

.progress-text .text {
  line-height: 40rpx;
  display: inline-block;
  vertical-align: middle;
}
</style>
